/***************************************************************************
 *                                                                         *
 *   This file is part of the CrystalMem project,                          *
 *       http://code.google.com/p/crystalmem                               *
 *                                                                         *
 *   Copyright (C) 2008 by Alberto Scarpa <scarpa.alberto@gmail.com>       *
 *   Copyright (C) 2008 by Enrico Ros <enrico.ros@gmail.com>               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef __TreeBuilder_h__
#define __TreeBuilder_h__

#include <QObject>
#include <QUdpSocket>
class MemoryTree;
class ProgramNode;

class TreeBuilder : public QObject {
    Q_OBJECT
    public:
        TreeBuilder( MemoryTree * memoryTree, quint16 listenPort = 1337, QObject * parent = 0 );
        ~TreeBuilder();

        bool loadFromFile( const QString & fileName = "../input-sample" );
        quint32 readBacktrace( const char *buf );

    Q_SIGNALS:
        void treeUpdated();

    private:
        MemoryTree *    m_memTree;
        QUdpSocket *    m_udpSocket;
        struct AllocationEntry {
            ProgramNode *node;
            quint32 size;
        };
        QHash<quint32, AllocationEntry *> m_allocatedAddresses;

    private Q_SLOTS:
        void slotDatagramReceived();
};

#endif
